package org.istone.mylife.component.security.actor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.istone.mylife.component.security.Property;
import org.istone.mylife.component.security.User;
import org.istone.mylife.component.security.authentication.Passphrase;
import org.istone.mylife.component.security.authentication.Password;
import org.istone.mylife.component.security.authorization.Privilege;
import org.istone.mylife.component.security.authorization.Role;

/**
 * @author Stone
 * @date Dec 20, 2011 12:04:51 AM
 */
public class SystemUser implements User {

    private static final long serialVersionUID = -7658431419041411987L;

    // 此处是否有更好的线程安全的集合可用？
    private Map<String, Property> properties;

    /**
     * @return
     */
    @Override
    public String getName() {
	return null;
    }

    /**
     * @return
     */
    @Override
    public Passphrase getPassphrase() {
	// TODO Auto-generated method stub
	return null;
    }

    /**
     * @return
     */
    @Override
    public Password getPassword() {
	// TODO Auto-generated method stub
	return null;
    }

    /**
     * @return
     */
    @Override
    public Privilege[] getPrivileges() {
	// TODO Auto-generated method stub
	return null;
    }

    /**
     * @return
     */
    @Override
    public Property[] getProperties() {
	// TODO Auto-generated method stub
	return null;
    }

    /**
     * @param key
     *            需获取属性的属性名
     * @return 根据属性名获取的用户属性
     */
    @Override
    public Property getProperty(String name) {
	if (this.properties == null)
	    return null;
	return this.properties.get(name);
    }

    /**
     * @return
     */
    @Override
    public Role[] getRoles() {
	// TODO Auto-generated method stub
	return null;
    }

    @Override
    public void setName() {
	// TODO Auto-generated method stub

    }

    /**
     * @param passphrase
     */
    @Override
    public void setPassphrase(Passphrase passphrase) {
	// TODO Auto-generated method stub

    }

    /**
     * @param password
     */
    @Override
    public void setPassword(Password password) {
	// TODO Auto-generated method stub

    }

    /**
     * @param properties
     *            需为用户添加的一组属性
     */
    @Override
    public void setProperties(Property... properties) {
	if (this.properties == null) {
	    // 使用同步哈希图，出于线程安全性考虑
	    this.properties = new ConcurrentHashMap<String, Property>();
	}
	for (Property property : properties) {
	    this.properties.put(property.getName(), property);
	}
    }

    /**
     * @param property
     *            需为用户添加的单个属性
     */
    @Override
    public void setProperty(Property property) {
	setProperties(new Property[] { property });
    }
}
